import store from '@/store';
import { fetch } from '@/utils/fetch';

export function getVerificationCode() {
  return fetch({
    baseURL: process.env.VUE_APP_BASE_PATH,
    url: 'easysightInt/rest/sys/getVerificationCode',
    method: 'get'
  });
}

export function login(data) {
  return fetch({
    baseURL: process.env.VUE_APP_BASE_PATH,
    url: 'easysightInt/rest/sys/mainApp/login',
    method: 'post',
    data
  });
}

export function logout() {
  return fetch({
    baseURL: process.env.VUE_APP_BASE_PATH,
    url: `easysightInt/rest/sys/logout?token=${store.getters.token}`,
    method: 'get'
  });
}

export function loginBySmsCode(data) {
  return fetch({
    baseURL: process.env.VUE_APP_BASE_PATH,
    url: 'easysightInt/rest/sys/login/app/sms',
    method: 'post',
    data
  });
}

export function sendSmsCode(createPhone) {
  return fetch({
    baseURL: process.env.VUE_APP_BASE_PATH,
    url: `easysightInt/rest/sys/login/app/sendSms?createPhone=${createPhone}`,
    method: 'get'
  });
}

//  修改密码
export function modifyPsw(params) {
  let url = 'easysightInt/rest/manger/view/cust/pwd';
  url += `?token=${store.getters.token}`;
  return fetch({
    baseURL: process.env.VUE_APP_BASE_PATH,
    url,
    method: 'post',
    data: params
  });
}

//  获取token
export function getToken() {
  return fetch({
    baseURL: process.env.VUE_APP_BASE_PATH,
    url: `easysightInt/rest/sys/heart?token=${store.getters.token}`,
    method: 'get'
  });
}
